﻿using System;

namespace UniRx
{
	// Token: 0x02000395 RID: 917
	public static class SubjectExtensions
	{
		// Token: 0x060012A1 RID: 4769 RVA: 0x00055EB4 File Offset: 0x000542B4
		public static ISubject<T> Synchronize<T>(this ISubject<T> subject)
		{
			return new SubjectExtensions.AnonymousSubject<T>(subject.Synchronize<T>(), subject);
		}

		// Token: 0x060012A2 RID: 4770 RVA: 0x00055EC2 File Offset: 0x000542C2
		public static ISubject<T> Synchronize<T>(this ISubject<T> subject, object gate)
		{
			return new SubjectExtensions.AnonymousSubject<T>(subject.Synchronize(gate), subject);
		}

		// Token: 0x02000396 RID: 918
		private class AnonymousSubject<T, U> : ISubject<T, U>, IObserver<T>, IObservable<U>
		{
			// Token: 0x060012A3 RID: 4771 RVA: 0x00055ED1 File Offset: 0x000542D1
			public AnonymousSubject(IObserver<T> observer, IObservable<U> observable)
			{
				this.observer = observer;
				this.observable = observable;
			}

			// Token: 0x060012A4 RID: 4772 RVA: 0x00055EE7 File Offset: 0x000542E7
			public void OnCompleted()
			{
				this.observer.OnCompleted();
			}

			// Token: 0x060012A5 RID: 4773 RVA: 0x00055EF4 File Offset: 0x000542F4
			public void OnError(Exception error)
			{
				if (error == null)
				{
					throw new ArgumentNullException("error");
				}
				this.observer.OnError(error);
			}

			// Token: 0x060012A6 RID: 4774 RVA: 0x00055F13 File Offset: 0x00054313
			public void OnNext(T value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x060012A7 RID: 4775 RVA: 0x00055F21 File Offset: 0x00054321
			public IDisposable Subscribe(IObserver<U> observer)
			{
				if (observer == null)
				{
					throw new ArgumentNullException("observer");
				}
				return this.observable.Subscribe(observer);
			}

			// Token: 0x04000B3D RID: 2877
			private readonly IObserver<T> observer;

			// Token: 0x04000B3E RID: 2878
			private readonly IObservable<U> observable;
		}

		// Token: 0x02000397 RID: 919
		private class AnonymousSubject<T> : SubjectExtensions.AnonymousSubject<T, T>, ISubject<T>, ISubject<T, T>, IObserver<T>, IObservable<T>
		{
			// Token: 0x060012A8 RID: 4776 RVA: 0x00055F40 File Offset: 0x00054340
			public AnonymousSubject(IObserver<T> observer, IObservable<T> observable) : base(observer, observable)
			{
			}
		}
	}
}
